﻿using System.IO;
using System.Threading.Tasks;
using RayDen.GLPlayground;
using RayDen.Library.Components.SystemComponents;
using RayDen.Library.Data.Xml;
using RayDen.Library.Entity.Frames;
using RayDen.RayEngine;

namespace RayDen.RdfViewer.Controllers
{
    public class EngineController
    {
        public RayEngineConfiguration Config;

        public EngineController()
        {
            Config = new RayEngineConfiguration();
        }

        public void OpenFrame(string frameName)
        {
            FrameDescription frame;
            
            using (var frameFile = new FileStream(frameName, FileMode.Open, FileAccess.Read))
            {
                using (var reader = new StreamReader(frameFile))
                    frame = (FrameDescription)SerializationService.Deserialize(reader.ReadToEnd(), typeof(FrameDescription));
            }
            Tracer.TraceLine("Frame [[{0}]] loaded, start setuping renderer", frame.FrameName);
            frame.FrameName = Path.GetFileNameWithoutExtension(frameName);
            Config.OpenFrame(frame);
        }


        public Task StartRenderer()
        {
            return Task.Run(() =>
                {
                    using (var example = new TexturedQuadWindow(Config))
                        //using (var example = new MainWindow(re))
                    {
                        example.Run(0.067);
                    }
                });
        }



    }
}